import request from "@/utils/request.js";

export const listDishCategory = async () => {
    const res = await request.get('/dishCategory/list');
    return res.map(e => ({...e, value: e.id, label: e.name}))
}

export const listMerchant = async () => {
    const res = await request.get('/merchant/list');
    return res.map(e => ({...e, value: e.id, label: e.name}))
}

export const isHotOptions = [
    {value: 0, label: '否', type: 'primary'},
    {value: 1, label: '是', type: 'info'},
]

export const isNewOptions = [
    {value: 0, label: '否', type: 'primary'},
    {value: 1, label: '是', type: 'info'},
]

export const fields = [
    {
        prop: 'image',
        label: '菜品主图',
        type: 'image',
        width: 100,
    },
    {
        prop: 'merchantId',
        label: '所属商家',
        type: 'remote-select',
        api: listMerchant,
        width: 200,
        requireRoles: ['admin']
    },
    {
        prop: 'categoryId',
        label: '所属分类',
        type: 'remote-select',
        api: listDishCategory,
        width: 100,
    },
    {
        prop: 'name',
        label: '菜品名称',
        type: 'text',
        search: true,
        width: 200,
    },
    {
        prop: 'description',
        label: '描述',
        type: 'longtext',
        width: 140,
        required: false,
    },
    {
        prop: 'images',
        label: '菜品图片',
        type: 'image-list',
        width: 100,
    },
    {
        prop: 'price',
        label: '价格',
        type: 'number',
        width: 100,
    },
    {
        prop: 'stock',
        label: '库存',
        type: 'number',
        width: 100,
        rule: {
            min: 0,
            required: true,
            message: `库存必须大于0`,
            trigger: 'blur'
        }
    },
    {
        prop: 'sales',
        label: '销量',
        type: 'number',
        width: 100,
        formHidden: true,
    },
    {
        prop: 'rating',
        label: '评分',
        type: 'rating',
        width: 170,
        formHidden: true,
    },
    {
        prop: 'isHot',
        label: '是否热销',
        type: 'switch',
        options: isHotOptions,
        search: true,
        width: 130,
    },
    {
        prop: 'isNew',
        label: '是否新品',
        type: 'switch',
        options: isNewOptions,
        search: true,
        width: 130,
    },
    {
        prop: 'discount',
        label: '折扣率',
        type: 'number',
        width: 120,
    },
    {
        prop: 'createTime',
        label: '创建时间',
        type: 'datetime',
        formHidden: true,
        width: 190,
    },
    {
        prop: 'updateTime',
        label: '更新时间',
        type: 'datetime',
        formHidden: true,
        width: 190,
    }
]